package com.asura.framework.rulemodel;

/**
 * 规则模型类型常量类.
 * 
 * @author a123
 *
 */
public class RuleTypeEnum {

	public final static RuleTypeEnum SIMPLE = new RuleTypeEnum( 1, "简单类型" );

	public final static RuleTypeEnum NUMBER = new RuleTypeEnum( 2, "数值类型" );

	public final static RuleTypeEnum TIME = new RuleTypeEnum( 3, "时间类型" );

	public final static RuleTypeEnum AMOUNT = new RuleTypeEnum( 4, "金额类型" );

	private int type;

	private String note;

	public RuleTypeEnum( int type, String note )
	{
		this.type = type;
		this.note = note;
	}

	public int getType( )
	{
		return type;
	}

	public String getNote( )
	{
		return note;
	}

	@Override
	public String toString( )
	{
		StringBuilder tostr = new StringBuilder( );
		tostr.append( "[type=" ).append( type );
		tostr.append( ", note=" ).append( note );
		tostr.append( "]" );
		return tostr.toString( );
	}

	public static final RuleTypeEnum getRuleType( int type )
	{
		RuleTypeEnum[ ] rules =
		{ SIMPLE, NUMBER, TIME, AMOUNT };
		for ( RuleTypeEnum rule : rules )
		{
			if ( rule.getType( ) == type )
			{
				return new RuleTypeEnum( rule.getType( ), rule.getNote( ) );
			}
		}
		throw new IllegalStateException( "规则类型[type=" + type + "]错误" );
	}
}
